<!--
* 修改页面
* @author chenyi
* @email 228112142@QQ.com
* @date 2017-06-27 10:40:56
*-->
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <%@ include file="/common/jsp/resource.jsp" %>
</head>
<body>
<div class="layui-field-box">
    <form class="layui-form" action="">
        <input type="hidden" name="userId" value="${model.userId}">
        <div class="layui-form-item">
            <label class="layui-form-label">用户名<span class="span_must">*</span></label>
            <div class="layui-input-normal">
                <input type="text" name="username" value="${model.username}" lay-verify="required" placeholder="请输入用户名"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">邮箱<span class="span_must">*</span></label>
            <div class="layui-input-normal">
                <input type="text" name="email" value="${model.email}" lay-verify="required" placeholder="请输入邮箱"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">手机号<span class="span_must">*</span></label>
            <div class="layui-input-normal">
                <input type="text" name="mobile" value="${model.mobile}" lay-verify="required" placeholder="请输入手机号"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">角色<span class="label_span">:</span></label>
            <div cyType="checkboxTool" cyProps="url:'/sys/role/findAll',allBtn:'true'" name="roleIdList" value="${roleIdList}"
                 lay-verify="required"
                 class="layui-input-normal"></div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">状态<span class="span_must">&nbsp;*</span></label>
            <div cyType="radioTool" cyProps="codeName:'state'" name="status" value="${model.status}"
                 lay-verify="required"
                 class="layui-input-normal"></div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">

                <button class="layui-btn" lay-submit="" lay-filter="submit">保存</button>
                <button class="layui-btn" onclick="closeWindow()"> 返回</button>
            </div>
        </div>
    </form>
</div>
<script>
    layui.use(['form'], function () {
        var form = layui.form();
        //监听提交
        form.on('submit(submit)', function (data) {
            debugger;
            var url = "/sys/user/update";
            $.ajax({
                type: "post",
                url: url,
                contentType: "application/json",
                data: JSON.stringify(data.field),
                async: false,
                dataType: "json",
                success: function (R) {
                    if (R.code === 0) {
                        alert('操作成功', function (index) {
                            closeWindow();
                        });
                    } else {
                        alert(R.msg);
                    }
                },
                error: function () {
                    alert("系统繁忙");
                }
            });
            return false;
        });

        //监听单选
        form.on('radio(menuType_0)', function (data) {
            $(".layui-form-item").show();
            $("[name='url']").parent().parent().hide();
            $("[name='perms']").parent().parent().hide();
            form.render();
            return false;
        });
        form.on('radio(menuType_1)', function (data) {
            $(".layui-form-item").show();
            form.render();
            return false;
        });
        form.on('radio(menuType_2)', function (data) {
            $(".layui-form-item").show();
            $("[name='url']").parent().parent().hide();
            $("[name='order_num']").parent().parent().hide();
            $("[name='icon']").parent().parent().hide();
            form.render();
            return false;
        });

    });
    $(document).ready(function () {
        if ($("[lay-filter='menuType_0']").attr("checked") != undefined) {
            $("[name='url']").parent().parent().hide();
            $("[name='perms']").parent().parent().hide();
        }
        if ($("[lay-filter='menuType_2']").attr("checked") != undefined) {
            $("[name='url']").parent().parent().hide();
            $("[name='order_num']").parent().parent().hide();
            $("[name='icon']").parent().parent().hide();
        }
    });
</script>
</body>
</html>
